Repository navigation
DEV-1144: choose the link CRC from the firmware version, after reading it - #23
Merged
Merged
Conversation
…g it connect() turned a 2-byte CRC on before reading any version, so it could not know that two Shimmer3R LogAndStream ranges cannot carry one: - v1.00.024 to v1.00.049 build the unsolicited status push in a 6-byte buffer. Behind the default ACK prefix a 2-byte CRC makes the push 7 bytes, and the sensor hardfaults (DEV-621, fixed in v1.00.050). One CRC byte fits. - v1.00.010 and earlier turn the CRC off whenever sensing stops, so every reply after a stop arrives without the trailer this class strips. connect() now sends SET_CRC off, reads the firmware and device versions, then asks for strongestSafeCRCMode: 1 byte on the first range, none on the second, 2 bytes everywhere else as before. sendCRCCommand refuses any stronger mode, which also covers the public setCRCMode in #22. It also now sets CRCMode before the write, since the firmware applies the new mode to the command's own ACK. Unbuilt and untested: written without Xcode, so CI is the first compile. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JongChern
approved these changes
Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
connect()sent SET_CRC 2 on every connect, before it had read any version. So it could not know that two Shimmer3R LogAndStream ranges cannot carry a 2-byte CRC. It now reads the versions first, then asks for the strongest CRC that firmware carries safely.removeFirst.The two ranges
uint8_t selfcmd[6](ShimBt_instreamStatusRespSend, log-and-stream-commonComms/shimmer_bt_uart.c:2262at f39be8c1f, which v1.00.049 pins).S4Sens_stopSensingcallssetBtCrcMode(CRC_OFF)(shimmer3r-firmwareS3R_Production/S4_App/s4_sensing.c:354at v1.00.010; gone at v1.00.011).What changed
connect()now runs SET_CRC off, then the FW version, then the device version, then SET_CRC withstrongestSafeCRCMode. The last step is skipped when that mode is off.CRCModesurvives a disconnect, and the firmware's survives a link drop it never saw. The Java driver also resets the CRC first, and the protocol doc (§8.2) puts SET_CRC after the version reads.strongestSafeCRCMode(...)is a new static function that makes the decision from the hardware, the firmware identifier and the version.sendCRCCommandrefuses any mode stronger than that, and returns false. That covers every later caller, notably add crc and PRR UI #22's publicsetCRCMode.sendCRCCommandnow setsCRCModebefore writing the command, not after. The firmware applies the new mode to the command's own ACK. The first command now switches down from a possibly stale mode, so an ACK handled in that gap wouldremoveFirstpast the end of the buffer.Why not the web SDK's fix
The web SDK (DEV-1141, ShimmerResearch/shimmer-web-sdk#183) keeps the 2-byte CRC and turns the push's ACK prefix off with 0xA3. Swift cannot take that route, because it parses no status pushes at all.
An unprefixed push starts with 0x8A, and the idle receive loop's
0xFFcheck never consumes it. Every later reply would queue behind it, and since there are no command timeouts, every later call would hang.Testing: unbuilt and untested
testStrongestSafeCRCModeinShimmerBluetoothTests, 14 assertions:connect()andsendCRCCommand.Shimmer3Protocolcannot be constructed in a test, becauseinitneeds a liveCBPeripheral.main, every reply Swift has ever parsed was under a 2-byte CRC, so this change runs the off path for the first time, on every connect and every device. It has been read, not run.Open PRs
setCRCModegoes throughsendCRCCommand, so the guard covers it whichever PR merges first.setCRCModereturns false, and the active-mode text stays correct.Not covered
🤖 Generated with Claude Code